home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Input into array of strings?
- Date: 8 Mar 1996 14:56:26 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4hphqq$ehd@sparcserver.lrz-muenchen.de>
- References: <4hnv1e$o7n@rhea.glo.be>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- sclaeys@glo.be (Sven Claeys) writes:
-
- >Hi,
-
- >I've got a some kind of problem reading into arrays of strings. I'm a
- >bit rusty in C or C++, it's been a while, so please be patient with
- >me.
-
- >here we go:
-
- >i've got a structure
-
- >struct ImmoData
- >{
- > char code[3][5];
-
- "code" is an array of 3 arrays of 5 characters.
-
- > ....
- >}....;
-
- >now i want to read data from a file with fgets(...) into this array.
-
- >I've tried
- > for (i=0; i<5; i++)
- > fgets(code[i],....);
-
- code[i] is an array of 5 characters, and accessing the 4th and the 5th
- element of an array of 3 (arrays of 5 characters) is very unwise.
-
- >or
- > for (i=0; i<5; i++)
- > fgets((char*) code[i], ...);
-
- code[i] is an array of 5 characters, and decays to a pointer to char
- in an expression context without further help. The cast does not do
- anything.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-